import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';

class ACWebView extends StatelessWidget {
  final String url;
  final String title;

  const ACWebView({super.key, required this.url, required this.title});

  @override
  Widget build(BuildContext context) {
    WebViewController controller = WebViewController()
      ..setJavaScriptMode(JavaScriptMode.unrestricted)
      ..setBackgroundColor(Colors.white)
      ..setNavigationDelegate(
        NavigationDelegate(
          onProgress: (int progress) {
            // Update loading bar.
          },
          onPageStarted: (String url) {},
          onPageFinished: (String url) {},
          onWebResourceError: (WebResourceError error) {},
          onNavigationRequest: (NavigationRequest request) {
            if (request.url.startsWith('https://www.youtube.com/')) {
              return NavigationDecision.prevent;
            }
            return NavigationDecision.navigate;
          },
        ),
      )
      ..loadRequest(Uri.parse(url));

    return Scaffold(
      // extendBodyBehindAppBar: true,
      appBar: AppBar(
        title: Text(title),
        backgroundColor: Colors.transparent,
      ),
      body: Container(
        decoration: const BoxDecoration(
          image: DecorationImage(
            image: AssetImage('assets/images/appbackground.png'),
            // 替换为你的背景图片路径
            fit: BoxFit.cover,
          ),
        ),
        child:  WebViewWidget(controller: controller),
      ),
      // body: WebViewWidget(controller: controller),
    );
  }
}
